//
//  YCCarServiceDetailViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/6.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  班车服务详情

#import "YCCarServiceDetailViewController.h"

#pragma mark - YCCarServiceDetailCell

@interface YCCarServiceDetailCell : UITableViewCell

@property (nonatomic, strong) UILabel *lineNameLabel;
@property (nonatomic, strong) UILabel *stationLabel;
@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation YCCarServiceDetailCell

+ (BOOL)requiresConstraintBasedLayout
{
    return YES;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        UILabel *lineNameLabel = [[UILabel alloc] init];
        lineNameLabel.text = @"十四治安装公司";
        lineNameLabel.font= [UIFont boldSystemFontOfSize:13];
        lineNameLabel.textColor = [UIColor blackColor];
        self.lineNameLabel = lineNameLabel;
        [self.contentView addSubview:lineNameLabel];
        
        UIImageView *locImageView = [[UIImageView alloc] init];
        locImageView.image = [UIImage imageNamed:@"灰坐标"];//28*28px
        [self.contentView addSubview:locImageView];
        
        UILabel *stationLabel = [[UILabel alloc] init];
        stationLabel.font = [UIFont systemFontOfSize:12];
        stationLabel.text = @"西站立交桥";
        stationLabel.textColor = [UIColor yc_colorWithUInt:0x808080];
        self.stationLabel = stationLabel;
        [self.contentView addSubview:stationLabel];
        
        UIImageView *timeImageView = [[UIImageView alloc] init];
        timeImageView.image = [UIImage imageNamed:@"时间"];//28*28px
        [self.contentView addSubview:timeImageView];
        
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.font = [UIFont systemFontOfSize:12];
        timeLabel.numberOfLines = 0;
        timeLabel.text = @"7:00 7:00 7:00 7:00 7:00 7:00 7:00 ";
        timeLabel.textColor = [UIColor yc_colorWithUInt:0x808080];
        self.timeLabel = timeLabel;
        [self.contentView addSubview:timeLabel];
        
        
        [lineNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(18);
            make.top.equalTo(self.contentView).offset(0);
        }];
        
        [locImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(lineNameLabel.mas_bottom).offset(12);
            make.width.height.equalTo(@14);
        }];
        
        [stationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(locImageView.mas_right).offset(6);
            make.centerY.equalTo(locImageView);
        }];
        
        [timeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(locImageView.mas_bottom).offset(6);
            make.width.height.equalTo(@14);
        }];
        
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeImageView.mas_right).offset(6);
            make.centerY.equalTo(timeImageView);
            make.right.equalTo(self.contentView).offset(15);
        }];
    }
    return self;
}

@end

#pragma mark - YCCarServiceDetailViewController

@interface YCCarServiceDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

/** 表  */
@property (nonatomic, strong) UITableView *tableView;
/** 顶部标题  */
@property (nonatomic, strong) UIView *topView;
/** 数据  */
@property (nonatomic, strong) NSArray *dataArray;

/** 班车线名  */
@property (nonatomic, strong) UILabel *lineNameLabel;
@property (nonatomic, strong) YCCarServiceModel *model;

@end

@implementation YCCarServiceDetailViewController

//- (NSArray *)dataArray
//{
//    if (!_dataArray) {
//        _dataArray = @[
//                       @"十四治安装公司",
//                       @"云南师范大学",
//                       @"油管桥",
//                       @"理工大学迎新校区",
//                       @"延安医院",
//                       ];
//    }
//    return _dataArray;
//}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.yc_width, self.view.yc_height-64) style:UITableViewStylePlain];
        //        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.rowHeight = 102;//
        _tableView.tableHeaderView = self.topView;
        _tableView.tableFooterView = [[UIView alloc] init];
//      _tableView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    }
    return _tableView;
}

- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 76)];
    
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth - 145)/2.0, 15, 145, 28)];
        bgView.backgroundColor = [UIColor blackColor];
        [_topView addSubview:bgView];
        
        UIImageView *carImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"班车详情"]];//27*30px
        [bgView addSubview:carImageView];
        
        UILabel *lineNameLabel = [[UILabel alloc] init];
        lineNameLabel.text = @"昆明市区A线";
        lineNameLabel.font = [UIFont systemFontOfSize:13];
        lineNameLabel.textColor = [UIColor whiteColor];
        lineNameLabel.textAlignment = NSTextAlignmentCenter;
        self.lineNameLabel = lineNameLabel;
        [bgView addSubview:lineNameLabel];
        
        [carImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(bgView);
            make.left.equalTo(bgView).offset(20);
            make.width.equalTo(@14);
            make.height.equalTo(@15);
        }];
        
        [lineNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(bgView);
            make.left.equalTo(carImageView.mas_right).offset(13);
            make.right.equalTo(bgView).offset(-13);
        }];
        
    }
    return _topView;
}

#pragma mark - 生命周期

- (instancetype)initWithCarServiceModel:(YCCarServiceModel *)model
{
    if (self = [super init]) {
        _model = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self yc_addBackBarButtonItem];
    self.navigationItem.title = @"班车详情";
//    [self.view addSubview:self.topView];
    [self.view addSubview:self.tableView];
    self.lineNameLabel.text = self.model.title;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return self.dataArray.count;
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCCarServiceDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"carServiceDetailCell"];
    if (!cell) {
        cell = [[YCCarServiceDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"carServiceDetailCell"];
    }
    YCCarServiceDetailModel *detailModel = self.model.info;
    cell.lineNameLabel.text = detailModel.name;//self.dataArray[indexPath.row];
    cell.stationLabel.text = detailModel.position;
    cell.timeLabel.text = detailModel.time;
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCLogFunc
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
